import elementtree.ElementTree as ET
import string

class template_parser:
    def __init__(self,filename):
        self.File = filename
        self.Tree = ET.parse(self.File)
        self.attributes = []
                
    def get_answer(self):        
        answer = "";
        index = 0
        iter = self.Tree.getiterator()
        for element in iter:
            if element.tag == "Textinput": #or element.tag == "Textarea":
                if element.text is not None:
                    for valueelement in element.getchildren():
                        if valueelement.tag == "Value":
                            if index != 0 :
                                answer = answer + ","
                            for statisticelement in valueelement.getchildren():
                                if statisticelement.tag == "Statistic":
                                    if statisticelement.text is not None:
                                        answer = answer + statisticelement.text + " of " + element.text
                                        index = index + 1
                                    else:
                                        answer = answer + "all values of " + element.text
                                        index = index + 1
                            if len(valueelement.getchildren()) == 0:
                                    answer = answer + "all values of " + element.text
                                    index = index + 1
        return answer    

   
    def get_patient(self, mrn):
       if mrn is not None:
           patient = "mrn = "+ str(mrn)
       else:
           patient = ""           
       return patient
    
    def get_cond(self, bedno):
        if bedno is not None:
            cond = "bedno = Bed " + str(bedno).strip()
        else:
            cond = ""
        return cond
    
    def get_toc(self):
       toc = "SNOMED"
       return toc
    
    def get_db(self):
       db = "GICU"
       return db
    
    def get_diagnosis(self):
       diagnosis = ""
       return diagnosis
    
    def get_time_value(self):
       time_value = 24
       return time_value
    
    def get_time_ent(self):
       time_ent = "hours" #"weeks","days"
       return time_ent
    
    def get_ward(self):
       ward = "GICU" # "ICU","CICU"
       return ward
    
    def get_File(self):
       return self.File
    
    def get_Tree(self):
       return self.Tree
